<?php


namespace App\Http\Controllers\cms;


use App\Engine\BaseController;
use App\Models\Yuyue as YuyueModel;
use App\Models\User as UserModel;
use function app\Utils\go;
use App\Models\Sys as SysModel;

class Yuyue extends BaseController
{
    public function get()
    {
        $res=YuyueModel::with('user')->orderBy('id','desc')->get();
        return go($res);
    }

    public function update()
    {
        $res=YuyueModel::find($this->post['id'])->update($this->post);
        
        if($this->post['state']==1){
            $invite_id=UserModel::where('id',YuyueModel::where('id',$this->post['id'])->value('uid'))->value('invite_id');
            if($invite_id){
                 $yuyue_money=SysModel::getValue('yuyue_money');
                UserModel::where('id',$invite_id)->increment('money',$yuyue_money);
            }
        }
        return go($res);
    }

}
